<?php
/**
 * 功能: PhpStorm.
 * User: 文丹
 * Date: 2018/7/30 0030
 * Time: 14:43
 */

namespace app\index\controller;


use think\Controller;
use think\Db;

import('taobao/TopSdk',EXTEND_PATH);
class Test extends Controller{
   public function goods(){
      $res = Db::name('goods')
           ->where('gb_id',1)
           ->where('member_yongjin','>=',1)
           ->where('coupon_amount','>=',1)
           ->order('goods_price','desc')
           ->limit(100)
           ->select();
       echo "<pre>";
       print_r($res);
   }



    public function index(){
        $c = new \TopClient();
        $c->appkey = '25122605';
        //  config('appkey');
        $c->secretKey = 'b199cf8cdbf4fd26ac22d93ddf6033be';
        //  config('secretKey');
        $req = new \TbkDgMaterialOptionalRequest;
       // $req->setStartDsr("10");
        $req->setPageSize("20");
        $req->setPageNo("1");
        $req->setPlatform("2");
        $req->setEndTkRate("1");
        $req->setStartTkRate("1234");
        $req->setEndPrice("10");
        $req->setStartPrice("10");
        $req->setIsOverseas("false");
        $req->setIsTmall("false");
        $req->setSort("tk_rate_des");
       // $req->setItemloc("杭州");
       // $req->setCat("16,18");
        $req->setQ('女装');
        $req->setHasCoupon("false");
       // $req->setIp("13.2.33.4");
        $req->setAdzoneId("44266100434");
        /*$req->setNeedFreeShipment("true");
        $req->setNeedPrepay("true");
        $req->setIncludePayRate30("true");
        $req->setIncludeGoodRate("true");
        $req->setIncludeRfdRate("true");
        $req->setNpxLevel("2");*/
        $resp = $c->execute($req);
        echo "<pre>";
        print_r($resp);
    }

    public function material(){
        $c = new \TopClient();

        $c = new \TopClient();
        $c->appkey = '25122605';
        //  config('appkey');
        $c->secretKey = 'b199cf8cdbf4fd26ac22d93ddf6033be';
        $req = new \TbkDgMaterialOptionalRequest;
        // $req->setStartDsr("10");
        $req->setEndPrice("10");
        $req->setStartPrice("10");
        $req->setPlatform("2");//无线端
        $req->setEndTkRate("1");
        $req->setStartTkRate("1234");
        /*$req->setEndTkRate("1");
        $req->setStartTkRate("1234");*/
        //$req->setEndPrice("10");//折扣上限
        //  $req->setStartPrice("10");//折扣下限
        $req->setIsOverseas("false");
        $req->setIsTmall("false");
        $req->setSort('tk_rate_des');
        // $req->setItemloc("杭州");
        // $req->setCat("16,18");
        $req->setQ('女装');
        $req->setHasCoupon('true');
        // $req->setIp("13.2.33.4");
        $req->setAdzoneId('44266100434');
        /*$req->setNeedFreeShipment("true");
        $req->setNeedPrepay("true");
        $req->setIncludePayRate30("true");
        $req->setIncludeGoodRate("true");
        $req->setIncludeRfdRate("true");
        $req->setNpxLevel("2");*/
        $resp = $c->execute($req);

        $result =  json_decode(json_encode( $resp),true);
        echo "<pre>";
        print_r($resp);
    }

    /**
     * 粉丝数计算
     */
    public function member(){
        $user_id = intval(input('user_id',1));
        $amount = 1;

        Db::name('user')->where('id',$user_id)->setInc('total',$amount);
        Db::name('user')->where('id',$user_id)->setInc('commission',$amount);

        if($user_id){
            $parent = Db::name('user')->where('parent_id',$user_id)->find();
            $member = intval($parent['member']+1);
            Db::name('user')->where('user')->where('id',$parent['id'])->update(['member'=>$member]);

            $parent2 = Db::name('user')->where('parent_id',$parent['id'])->find();
            if($parent2){
                $member2 = intval($parent2['member']+1);
                Db::name('user')->where('user')->where('id',$parent['id'])->update(['member'=>$member2]);
            }
        }
    }

    /**
     * taobao.tbk.item.recommend.get( 淘宝客商品关联推荐查询 )
     */
    public function recommend(){
        $c = new \TopClient;
        $c->appkey = config('appkey');
        $c->secretKey = config('secret');
        $req = new \TbkItemRecommendGetRequest;
        $req->setFields("num_iid,title,pict_url,small_images,reserve_price,zk_final_price,user_type,provcity,item_url");
        $req->setNumIid("569449905472");
        $req->setCount("20");
        $req->setPlatform("1");
        $resp = $c->execute($req);
        echo "<pre>";
        print_r($resp);
    }

    /**
     * taobao.tbk.sc.order.get( 淘宝客订单查询 - 社交 )
     */
    public function order(){
        $c = new \TopClient;
        $c->appkey = config('appkey');
        $c->secretKey = config('secret');
        $req = new \TbkScOrderGetRequest;
        $req->setFields("tb_trade_parent_id,tb_trade_id,num_iid,item_title,item_num,price,pay_price,seller_nick,seller_shop_title,commission,commission_rate,unid,create_time,earning_time,tk3rd_pub_id,tk3rd_site_id,tk3rd_adzone_id,relation_id,tb_trade_parent_id,tb_trade_id,num_iid,item_title,item_num,price,pay_price,seller_nick,seller_shop_title,commission,commission_rate,unid,create_time,earning_time,tk3rd_pub_id,tk3rd_site_id,tk3rd_adzone_id,special_id");
        $req->setStartTime("2016-05-23 12:18:22");
        $req->setSpan("600");
        $req->setPageNo("1");
        $req->setPageSize("20");
        $req->setTkStatus("1");
        $req->setOrderQueryType("settle_time");
        $req->setOrderScene("1");
       // $resp = $c->execute($req, $sessionKey);
    }

    public function buqf(){

        $str = "Hello World123!";
        $str = strtoupper($str);
        echo $str; // 打印 HELLO WORLD
    }
    public function daxie(){
        $res = Db::name('user')->select();
        foreach($res as $k=>$v){
           $mark = Db::name('user')->where('id',$v['id'])->value('mark');
            $a = strtoupper($mark);
              Db::name('user')->where('id',$v['id'])->update(['mark'=>$a]);
        }


    }



}